//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.mega.ycy.common.event;

import com.mega.ycy.Yiciyuan_EVENT;
import com.mega.ycy.mixin.TWEAKER;
import mods.flammpfeil.slashblade.client.renderer.entity.layers.EntityLivingRenderHandler;
import mods.flammpfeil.slashblade.client.renderer.entity.layers.LayerSlashBlade;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.entity.RenderLivingBase;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.Timer;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

@Mod.EventBusSubscriber
public class SlashUpdateEvent extends EntityLivingRenderHandler {
    static LayerSlashBlade layer = null;

    static LayerSlashBlade getLayer(RenderLivingBase<?> render) {
        if (layer == null) {
            layer = new LayerSlashBlade(render);
        }

        return layer;
    }

    public SlashUpdateEvent() {
    }

    @SubscribeEvent
    public void RenderPlayerHandler(RenderPlayerEvent.Pre event) {
        if (Yiciyuan_EVENT.isSafe(event.getEntityLiving())) {
            layer = getLayer(event.getRenderer());
            GlStateManager.pushMatrix();
            GlStateManager.translate(event.getX(), event.getY(), event.getZ());
            EntityLivingBase entity = event.getEntityLiving();
            GlStateManager.translate(0.0F, -0.125F, 0.0F);

            if (entity instanceof AbstractClientPlayer) {
                AbstractClientPlayer player = (AbstractClientPlayer)entity;
                float yaw = interpolateRotation(entity.prevRenderYawOffset, entity.renderYawOffset, event.getPartialRenderTick());
                this.applyRotations(player, yaw, event.getPartialRenderTick());
            }

            layer.func_177141_a(event.getEntityLiving(), 0.0F, 0.0F, event.getPartialRenderTick(), 0.0F, 0.0F, 0.0F, 0.0F);
            GlStateManager.popMatrix();
        }
    }

    public static boolean isTimestop() {
        return TWEAKER.isTimeStop;
    }

    public static void setTimestop(Boolean b) {
        TWEAKER.isTimeStop = b;
        //if (TWEAKER.isTimeStop) {
        //    Minecraft.getMinecraft().timer.tickLength = Integer.MAX_VALUE;
        //} else Minecraft.getMinecraft().timer = new Timer(20.0F);
    }
}
